package com.sunshine.wrongquestionset.activity.my_subject

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import com.sunshine.wrongquestionset.room.entity.QuestionSetEntity
import com.sunshine.wrongquestionset.room.entity.SubjectEntity
import com.sunshine.wrongquestionset.room.repository.MyRepository

/**
 * @author sunshine
 * @date 2021/3/29
 */
class MySubjectViewModel(application: Application): AndroidViewModel(application) {
    private val repository: MyRepository = MyRepository(application.applicationContext)

    fun getMySubject(userId: String): LiveData<List<SubjectEntity>?> {
        return repository.getAllSubject(userId)
    }

    fun addSubject(userId: String, name: String) {
        repository.insertSubject(userId, name)
    }

    fun toDelete(subjectEntity: SubjectEntity?) {
        repository.deleteSubjectByEntity(subjectEntity)
    }

    fun updateSubject(subjectEntity: SubjectEntity?) {
        repository.updateSubject(subjectEntity)
    }

    fun getSetCountInSubjectId(subjectId: Int): LiveData<Int> {
        return repository.getQuestionSetCountInSubjectId(subjectId)
    }

}